<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>${SYSTEM_NAME}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/js/zTree_v3/css/metroStyle/metroStyle.css?v=${FILE_VERSION}" type="text/css">
</head>
<body>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-header">机构管理</div>
		<div class="layui-card-body">
			<div class="layui-row layui-col-space10">
				<div class="layui-col-xs2">
					<div style="border: 1px solid #ccc;max-height: 550px;min-height:400px; overflow: auto;">
						<ul id="treeRegion" class="ztree">
							机构加载中......
						</ul>
					</div>
				</div>

				<div class="layui-col-xs10" style="padding-left: 15px">
					<div class="layui-form layer-query" >
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">名称：</label>
								<div class="layui-input-inline">
									<input type="text" name="name" placeholder="请输入机构名称" id="name" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layui-btn-primary layui-border-blue" onclick="reload(true)">查询</button>
							</div>
						</div>
					</div>
					<hr class="layui-bg-green">
					<table class="layui-table" lay-filter="tableList" id="layerTable">
					</table>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-primary layui-border-blue" onclick="addLayerLocal();">新增</button>
		<button class="layui-btn layui-btn-primary layui-border-blue" onclick="modi();">编辑</button>
		<button class="layui-btn layui-btn-primary layui-border-red" onclick="deleteBatch('/sys/org/del/deleteByIds');">删除</button>
	</div>
</script>

<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="dateTpl">
	{{  new Date(d.dateCreate).format("yyyy-MM-dd hh:mm:ss") }}
</script>

<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/js/zTree_v3/js/jquery.ztree.core.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/js/common/commOrgTree.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/js/common/coreTree-2.0.0.js?v=${FILE_VERSION}"></script>
<script>
	var table;
	layui.use(['table'], function() {
		//创建树结构
		createOrgTree(true,"/sys/org/list/listAllTree",false);
		table = layui.table;
		table.render({ //其它参数在此省略
			elem : '#layerTable',
			even :"true",
			toolbar: '#toolbar',
			defaultToolbar: ['filter', 'exports', 'print'],
			limit: 10,
			limits: [10,30,50,100],
			id: 'tableList',
			url: getContextPath() + '/sys/org/list/listInfo',
			page:true,
			method: 'post', //如果无需自定义HTTP类型，可不加该参数
			cols:  [[ //标题栏
				{checkbox: true, fixed: true}
				,{field:'name', minWidth:120,title:"名称"}
				,{field:'sort', width:80,sort: true,title:"排序"}
				,{field:'typeName', width:100,title:"类型"}
				,{fixed: 'right', width:260,title:"操作", toolbar: '#barDemo'}
			]],
			request: {
				pageName: 'current' //页码的参数名称，默认：page
				,limitName: 'size' //每页数据量的参数名，默认：limit
			}
		});

		//监听工具条
		table.on('tool(tableList)', function(obj){
			var data = obj.data;
			if(obj.event === 'del'){
				deleteById(data,obj,'/sys/org/del/deleteById');
			} else if(obj.event === 'edit'){
				addLayer('/sys/org/edit/input', obj.data.id);
			}
		});
	});
	function addLayerLocal(){
		addLayer('/sys/org/add/input?parentId='+ getCurrentSelectOrgNodeId());
	}

	function reload(isFirstPage){
		var params= {
			where: {
				"parentId": getCurrentSelectOrgNodeId(),
				"name" : $('#name').val()
			}
		};
		// 解决：翻页后下次点击树节点会查不到数据（但新增和编辑要保持原页码）
		if(isFirstPage){
			params.page= {curr: 1}; //从第1页开始
		}
		table.reload('tableList', params);
	}

	/**
	 * 树节点点击回调
	 * @param node
	 */
	function orgTreeClickCallback(node){
		reload();
	}
</script>
</body>
</html>